/*
 *  This file is part of LifeBudget - Copyright 2010 Clifton Eaton
 *  ------------------------------------------------------------------
 *  LifeBudget is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  LifeBudget is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with LifeBudget.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.lifebudget.app.persistence.dao;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

import org.lifebudget.app.client.mvc.model.CategoryAmount;

import com.google.appengine.api.datastore.Key;

/**
 * The Class CategoryAmountDAO. Data Access Object in for the persistence
 * layer to handle persisting a {@link CategoryAmount}. Annotated for JPA
 * persistence.
 */
@Entity
public class CategoryAmountDAO {

	/** The key. */
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Key key;
	
	/** The user id. */
	private String userId;
	
	/** The parent paycheck id. */
	private long parentPaycheckId;
	
	/** The category id. */
	private long categoryId;
	
	/** The amount. */
	private double amount;

	/**
	 * Instantiates a new category amount DAO.
	 *
	 * @param parentPaycheckId the parent paycheck id
	 * @param categoryId the category id
	 * @param amount the amount
	 */
	public CategoryAmountDAO(long parentPaycheckId, long categoryId, double amount) {
		super();
		this.parentPaycheckId = parentPaycheckId;
		this.categoryId = categoryId;
		this.amount = amount;
	}

	/**
	 * Instantiates a new category amount DAO.
	 *
	 * @param ca the ca
	 */
	public CategoryAmountDAO(CategoryAmount ca) {
		this.parentPaycheckId = ca.getPaycheckCalcId();
		this.categoryId = ca.getCategory().getId();
		this.amount = ca.getAmount();
	}

	/**
	 * To model object.
	 *
	 * @return the category amount
	 */
	public CategoryAmount toModelObject() {
		CategoryAmount ca = new CategoryAmount(parentPaycheckId);
		ca.setAmount(amount);
		ca.setId(key.getId());
		return ca;
	}

	/**
	 * Sets the amount.
	 *
	 * @param amount the new amount
	 */
	public void setAmount(double amount) {
		this.amount = amount;
	}

	/**
	 * Gets the amount.
	 *
	 * @return the amount
	 */
	public double getAmount() {
		return amount;
	}

	/**
	 * Sets the category id.
	 *
	 * @param categoryId the new category id
	 */
	public void setCategoryId(long categoryId) {
		this.categoryId = categoryId;
	}

	/**
	 * Gets the category id.
	 *
	 * @return the category id
	 */
	public long getCategoryId() {
		return categoryId;
	}

	/**
	 * Sets the parent paycheck id.
	 *
	 * @param parentPaycheckId the new parent paycheck id
	 */
	public void setParentPaycheckId(long parentPaycheckId) {
		this.parentPaycheckId = parentPaycheckId;
	}

	/**
	 * Gets the parent paycheck id.
	 *
	 * @return the parent paycheck id
	 */
	public long getParentPaycheckId() {
		return parentPaycheckId;
	}

	/**
	 * Sets the key.
	 *
	 * @param key the new key
	 */
	public void setKey(Key key) {
		this.key = key;
	}

	/**
	 * Gets the key.
	 *
	 * @return the key
	 */
	public Key getKey() {
		return key;
	}

	/**
	 * Sets the user id.
	 *
	 * @param userId the new user id
	 */
	public void setUserId(String userId) {
		this.userId = userId;
	}

	/**
	 * Gets the user id.
	 *
	 * @return the user id
	 */
	public String getUserId() {
		return userId;
	}

	/**
	 * Sets the fields from model object.
	 *
	 * @param ca the new fields from model object
	 */
	public void setFieldsFromModelObject(CategoryAmount ca) {
		this.parentPaycheckId = ca.getPaycheckCalcId();
		this.categoryId = ca.getCategory().getId();
		this.amount = ca.getAmount();

	}

}
